//
//  HttpRequest.m
//  SmartLife
//
//  Created by Lawrence on 15/10/13.
//  Copyright © 2015年 Lawrence. All rights reserved.
//

#import "HttpRequest.h"
#import <AFNetworking.h>
@implementation HttpRequest
+(NSDictionary *) initWithUrl:(NSString *)url{
    HttpRequest *request=[[HttpRequest alloc]init];
    [request HttpRequest:url];
    return request.dict;
}
#pragma mark 解析JOSN数据
-(NSDictionary *)handlerJOSN:(NSData *)data{
    if (data!=nil) {
        NSError *error;
        NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
        return dict;
    }
    return nil;
}
-(void)HttpRequest:(NSString *)url{
     NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
        AFHTTPRequestOperation *operation=[[AFHTTPRequestOperation alloc] initWithRequest:request];
        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,id responseObject){
            //NSDictionary *dict=responseObject;
            //if (!=nil) {
            self.dict=[self handlerJOSN:(NSData *)responseObject];
            //}
        } failure:^(AFHTTPRequestOperation *operation, NSError * error) {
    
        }];
        NSOperationQueue *queue=[[NSOperationQueue alloc] init];
        [queue addOperation:operation];
}
@end
